import axios from "../util/request";

export function getClassifyList(val) {
  const { status, page, limit, title } = val;
  return axios({
    url: `/adminapi/setting/config_class?status=${status}&page=${page}&limit=${limit}&title=${title}`,
    method: "get",
  });
}

export function switchFun(val) {
  const { is_show, id } = val;
  return axios({
    url: `/adminapi/setting/config_class/set_status/${id}/${is_show}`,
    method: "PUT",
  });
}

export function switchfun(val) {
  const { is_show, id } = val;
  return axios({
    url: `/adminapi/setting/config/set_status/${id}/${is_show}`,
    method: "PUT",
  });
}

export function delList(val) {
  return axios({
    url: `/adminapi/setting/config_class/${val}`,
    method: "DELETE",
  });
}

export function dellist(val) {
  return axios({
    url: `/adminapi/setting/config/${val}`,
    method: "DELETE",
  });
}

export function tab(val) {
  const { tab_id, page, limit } = val;
  return axios({
    url: `/adminapi/setting/config?tab_id=${tab_id}&page=${page}&limit=${limit}`,
    method: "get",
  });
}

export function addCreateClassify() {
  return axios({
    url: `/adminapi/setting/config_class/create`,
    method: "GET",
  });
}

export function editCreateClassify(val) {
  return axios({
    url: `/adminapi/setting/config_class/${val}/edit`,
    method: "GET",
  });
}

export function confirmEdit(val) {
  const { id, eng_title, icon, pid, sort, status, title } = val;
  return axios({
    url: `/adminapi/setting/config_class/${id}`,
    method: "PUT",
    data: { eng_title, icon, pid, sort, status, title },
  });
}

export function confirmAdd(val) {
  const { eng_title, icon, pid, sort, status, title, type } = val;
  return axios({
    url: `/adminapi/setting/config_class`,
    method: "POST",
    data: { eng_title, icon, pid, sort, status, title, type },
  });
}

export function getAddRule(val) {
  const { tab_id, type } = val;
  return axios({
    url: `/adminapi/setting/config/create?type=${type}&tab_id=${tab_id}`,
    method: "get",
  });
}
export function querenAdd(val) {
  const {
    config_tab_id,
    desc,
    info,
    input_type,
    menu_name,
    required,
    sort,
    status,
    type,
    value,
    width,
    upload_type,
    parameter,
    high,
  } = val;
  let str = { ...type };

  if (type == 0) {
    str = "text";
  } else if (type == 1) {
    str = "textarea";
  } else if (type == 2) {
    str = "radio";
  } else if (type == 3) {
    str = "upload";
  } else if (type == 4) {
    str = "checkbox";
  } else {
    str = "select";
  }

  return axios({
    url: `/adminapi/setting/config`,
    method: "POST",
    data: {
      config_tab_id,
      desc,
      info,
      desc,
      input_type,
      menu_name,
      required,
      sort,
      status,
      value,
      width,
      upload_type,
      parameter,
      high,
      type: str,
    },
  });
}

export function getEditRule(val) {
  return axios({
    url: `/adminapi/setting/config/${val}/edit`,
    method: "get",
  });
}
export function querenEdit(val) {
  const {
    config_tab_id,
    desc,
    info,
    input_type,
    menu_name,
    required,
    sort,
    status,
    type,
    value,
    width,
    upload_type,
    parameter,
    high,
    id,
  } = val;
  let str = { ...type };

  if (type == 0) {
    str = "text";
  } else if (type == 1) {
    str = "textarea";
  } else if (type == 2) {
    str = "radio";
  } else if (type == 3) {
    str = "upload";
  } else if (type == 4) {
    str = "checkbox";
  } else {
    str = "select";
  }

  return axios({
    url: `/adminapi/setting/config/${id}`,
    method: "PUT",
    data: {
      config_tab_id,
      desc,
      info,
      desc,
      input_type,
      menu_name,
      required,
      sort,
      status,
      value,
      width,
      upload_type,
      parameter,
      high,
      type: str,
    },
  });
}
